package com.flowable.listener;

import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DemoListener extends AbstractFlowableEngineEventListener {
    @Override
    protected void taskAssigned(FlowableEngineEntityEvent event) {
        TaskEntity taskEntity = (TaskEntity)event.getEntity();
        log.info("taskEntity:{}", taskEntity);
    }

    // 监听流程启动（重写此方法）

    @Override
    protected void processStarted(FlowableProcessStartedEvent event) {
        super.processStarted(event);
        // 从事件中获取流程实例对象
        ProcessInstance processInstance = (ProcessInstance) event.getEntity();
        log.info("流程启动，流程实例ID：{}，流程定义ID：{}",
                processInstance.getId(),
                processInstance.getProcessDefinitionId());
    }
}
